<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">


<!-- remove old header -->


<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>cogen API Reference Documentation
        - Module: sockets</title><meta name="MSSmartTagsPreventParsing" content="true" /><meta http-equiv="imagetoolbar" content="no" /><link href="css/default.css" rel="stylesheet" type="text/css" /><link href="css/pygments.css" rel="stylesheet" type="text/css" />
    <!-- <link rel="shortcut icon" href="/images/favicon.ico" type="image/vnd.microsoft.icon"/> -->
    <link rel="stylesheet" href="css/apydia.css" type="text/css" />
    <script src="js/jquery-1.2.1.pack.js" type="text/javascript"></script>
    <script src="js/apydia.js" type="text/javascript"></script>
	<link rel="icon" href="images/favicon.ico" type="image/x-icon" />
</head>
<body>
    <div id="page">
        <div id="browser">
            <div class="browser-section">
                <h2>Module Index</h2>
                <ul>
                    <li>
                        <a href="cogen.html">cogen</a>
                    </li><li>
                        <a href="cogen.common.html">cogen.common</a>
                    </li><li>
                        <a href="cogen.core.html">cogen.core</a>
                    </li><li>
                        <a href="cogen.core.coroutines.html">cogen.core.coroutines</a>
                    </li><li>
                        <a href="cogen.core.events.html">cogen.core.events</a>
                    </li><li>
                        <a href="cogen.core.pubsub.html">cogen.core.pubsub</a>
                    </li><li>
                        <a href="cogen.core.queue.html">cogen.core.queue</a>
                    </li><li>
                        <a href="cogen.core.reactors.html">cogen.core.reactors</a>
                    </li><li>
                        <a href="cogen.core.reactors.base.html">cogen.core.reactors.base</a>
                    </li><li>
                        <a href="cogen.core.reactors.iocp_proactor.html">cogen.core.reactors.iocp_proactor</a>
                    </li><li>
                        <a href="cogen.core.reactors.poll_reactor.html">cogen.core.reactors.poll_reactor</a>
                    </li><li>
                        <a href="cogen.core.reactors.qt_reactor.html">cogen.core.reactors.qt_reactor</a>
                    </li><li>
                        <a href="cogen.core.reactors.select_reactor.html">cogen.core.reactors.select_reactor</a>
                    </li><li>
                        <a href="cogen.core.schedulers.html">cogen.core.schedulers</a>
                    </li><li class="active">
                        <a href="cogen.core.sockets.html">cogen.core.sockets</a>
                    </li><li>
                        <a href="cogen.core.util.html">cogen.core.util</a>
                    </li><li>
                        <a href="cogen.web.html">cogen.web</a>
                    </li><li>
                        <a href="cogen.web.async.html">cogen.web.async</a>
                    </li><li>
                        <a href="cogen.web.wsgi.html">cogen.web.wsgi</a>
                    </li>
                </ul>
            </div>
            <div class="browser-section">
                <h2>Classes</h2>
                <ul>
                    <li>
                        <a href="cogen.core.sockets.Accept.html">Accept</a>
                    </li><li>
                        <a href="cogen.core.sockets.Connect.html">Connect</a>
                    </li><li>
                        <a href="cogen.core.sockets.Read.html">Read</a>
                    </li><li>
                        <a href="cogen.core.sockets.ReadAll.html">ReadAll</a>
                    </li><li>
                        <a href="cogen.core.sockets.ReadLine.html">ReadLine</a>
                    </li><li>
                        <a href="cogen.core.sockets.SendFile.html">SendFile</a>
                    </li><li>
                        <a href="cogen.core.sockets.Socket.html">Socket</a>
                    </li><li>
                        <a href="cogen.core.sockets.SocketOperation.html">SocketOperation</a>
                    </li><li>
                        <a href="cogen.core.sockets.Write.html">Write</a>
                    </li><li>
                        <a href="cogen.core.sockets.WriteAll.html">WriteAll</a>
                    </li>
                </ul>
            </div>
            <div class="browser-section">
                <h2>Functions</h2>
                <ul>
                    <li>
                        <a href="cogen.core.sockets.html#function-getdefaulttimeout">getdefaulttimeout</a>
                    </li><li>
                        <a href="cogen.core.sockets.html#function-setdefaulttimeout">setdefaulttimeout</a>
                    </li>
                </ul>
            </div>
        </div>
        <div id="content">
    <h1>Module:
        cogen.core.sockets
    </h1>
    <div class="docstring rst"><p>Socket-only coroutine operations and <cite>Socket</cite> wrapper.
Really - the only thing you need to know for most stuff is
the <a class="reference" href="cogen.core.sockets.Socket.html">Socket</a> class.</p>
</div>
    <ul class="link-bar">
    <li class="link-to-sourcecode">
        <a href="http://code.google.com/p/cogen/source/browse/trunk/cogen/core/sockets.py#1">View source</a>
    </li>
</ul>
    <div>
        <h2>Classes</h2>
            <h3>
                <a href="cogen.core.sockets.Accept.html">Accept</a>
            </h3>
            <div class="docstring rst"><p>Returns a (conn, addr) tuple when the operation completes.</p>
</div>
            <ul class="link-bar">
    <li>
        <a href="cogen.core.sockets.Accept.html">Details</a>
    </li>
    <li class="link-to-sourcecode">
        <a href="http://code.google.com/p/cogen/source/browse/trunk/cogen/core/sockets.py#742">View source</a>
    </li>
</ul>
            <h3>
                <a href="cogen.core.sockets.Connect.html">Connect</a>
            </h3>
            <div class="docstring rst"></div>
            <ul class="link-bar">
    <li>
        <a href="cogen.core.sockets.Connect.html">Details</a>
    </li>
    <li class="link-to-sourcecode">
        <a href="http://code.google.com/p/cogen/source/browse/trunk/cogen/core/sockets.py#797">View source</a>
    </li>
</ul>
            <h3>
                <a href="cogen.core.sockets.Read.html">Read</a>
            </h3>
            <div class="docstring rst"><p>Example usage:</p>
<div class="source"><pre><span class="k">yield</span> <span class="n">sockets</span><span class="o">.</span><span class="n">Read</span><span class="p">(</span><span class="n">socket_object</span><span class="p">,</span> <span class="n">buffer_length</span><span class="p">)</span>
</pre></div>
<p><cite>buffer_length</cite> is max read size, BUT, if if there are buffers from ReadLine
return them first.</p>
</div>
            <ul class="link-bar">
    <li>
        <a href="cogen.core.sockets.Read.html">Details</a>
    </li>
    <li class="link-to-sourcecode">
        <a href="http://code.google.com/p/cogen/source/browse/trunk/cogen/core/sockets.py#401">View source</a>
    </li>
</ul>
            <h3>
                <a href="cogen.core.sockets.ReadAll.html">ReadAll</a>
            </h3>
            <div class="docstring rst"><p>Run this operation till we've read <cite>len</cite> bytes.</p>
</div>
            <ul class="link-bar">
    <li>
        <a href="cogen.core.sockets.ReadAll.html">Details</a>
    </li>
    <li class="link-to-sourcecode">
        <a href="http://code.google.com/p/cogen/source/browse/trunk/cogen/core/sockets.py#467">View source</a>
    </li>
</ul>
            <h3>
                <a href="cogen.core.sockets.ReadLine.html">ReadLine</a>
            </h3>
            <div class="docstring rst"><p>Run this operation till we read a newline (n) or we have a overflow.</p>
</div>
            <ul class="link-bar">
    <li>
        <a href="cogen.core.sockets.ReadLine.html">Details</a>
    </li>
    <li class="link-to-sourcecode">
        <a href="http://code.google.com/p/cogen/source/browse/trunk/cogen/core/sockets.py#548">View source</a>
    </li>
</ul>
            <h3>
                <a href="cogen.core.sockets.SendFile.html">SendFile</a>
            </h3>
            <div class="docstring rst"><p>Uses underling OS sendfile call or a regular memory copy operation if
there is no sendfile.
You can use this as a WriteAll if you specify the length.
Usage:</p>
<div class="source"><pre>yield sockets.SendFile(file_object, socket_object, 0, blocksize=0)
    # there will be only one send operation (if successfull)
    # that meas the whole file will be read in memory if there is
    #no sendfile

yield sockets.SendFile(file_object, socket_object, 0, file_size)
    # this will hang if we can't read file_size bytes
    #from the file
</pre></div>
</div>
            <ul class="link-bar">
    <li>
        <a href="cogen.core.sockets.SendFile.html">Details</a>
    </li>
    <li class="link-to-sourcecode">
        <a href="http://code.google.com/p/cogen/source/browse/trunk/cogen/core/sockets.py#294">View source</a>
    </li>
</ul>
            <h3>
                <a href="cogen.core.sockets.Socket.html">Socket</a>
            </h3>
            <div class="docstring rst"><p>A wrapper for socket objects, sets nonblocking mode and
adds some internal bufers and wrappers. Regular calls to the usual
socket methods return operations for use in a coroutine.</p>
<p>So you use this in a coroutine like:</p>
<div class="source"><pre><span class="n">sock</span> <span class="o">=</span> <span class="n">Socket</span><span class="p">(</span><span class="n">family</span><span class="p">,</span> <span class="nb">type</span><span class="p">,</span> <span class="n">proto</span><span class="p">)</span> <span class="c"># just like the builtin socket module</span>
<span class="k">yield</span> <span class="n">sock</span><span class="o">.</span><span class="n">read</span><span class="p">(</span><span class="mf">1024</span><span class="p">)</span>
</pre></div>
<p>Constructor details:</p>
<div class="source"><pre><span class="n">Socket</span><span class="p">([</span><span class="n">family</span><span class="p">[,</span> <span class="nb">type</span><span class="p">[,</span> <span class="n">proto</span><span class="p">]]])</span> <span class="o">-&gt;</span> <span class="n">socket</span> <span class="nb">object</span>
</pre></div>
<p>Open a socket of the given type.  The family argument specifies the
address family; it defaults to AF_INET.  The type argument specifies
whether this is a stream (SOCK_STREAM, this is the default)
or datagram (SOCK_DGRAM) socket.  The protocol argument defaults to 0,
specifying the default protocol.  Keyword arguments are accepted.</p>
<p>A socket object represents one endpoint of a network connection.</p>
</div>
            <ul class="link-bar">
    <li>
        <a href="cogen.core.sockets.Socket.html">Details</a>
    </li>
    <li class="link-to-sourcecode">
        <a href="http://code.google.com/p/cogen/source/browse/trunk/cogen/core/sockets.py#47">View source</a>
    </li>
</ul>
            <h3>
                <a href="cogen.core.sockets.SocketOperation.html">SocketOperation</a>
            </h3>
            <div class="docstring rst"><p>This is a generic class for a operation that involves some socket call.</p>
<p>A socket operation should subclass WriteOperation or ReadOperation, define a
<cite>run</cite> method and call the __init__ method of the superclass.</p>
</div>
            <ul class="link-bar">
    <li>
        <a href="cogen.core.sockets.SocketOperation.html">Details</a>
    </li>
    <li class="link-to-sourcecode">
        <a href="http://code.google.com/p/cogen/source/browse/trunk/cogen/core/sockets.py#192">View source</a>
    </li>
</ul>
            <h3>
                <a href="cogen.core.sockets.Write.html">Write</a>
            </h3>
            <div class="docstring rst"><p>Write the buffer to the socket and return the number of bytes written.</p>
</div>
            <ul class="link-bar">
    <li>
        <a href="cogen.core.sockets.Write.html">Details</a>
    </li>
    <li class="link-to-sourcecode">
        <a href="http://code.google.com/p/cogen/source/browse/trunk/cogen/core/sockets.py#661">View source</a>
    </li>
</ul>
            <h3>
                <a href="cogen.core.sockets.WriteAll.html">WriteAll</a>
            </h3>
            <div class="docstring rst"><p>Run this operation till all the bytes have been written.</p>
</div>
            <ul class="link-bar">
    <li>
        <a href="cogen.core.sockets.WriteAll.html">Details</a>
    </li>
    <li class="link-to-sourcecode">
        <a href="http://code.google.com/p/cogen/source/browse/trunk/cogen/core/sockets.py#700">View source</a>
    </li>
</ul>
    </div>
    <div>
        <h2>Functions</h2>
            <h3 id="function-getdefaulttimeout">
                getdefaulttimeout
                <span class="args">()</span>
            </h3>
            <div class="docstring rst"></div>
            <ul class="link-bar">
    <li class="link-to-sourcecode">
        <a href="http://code.google.com/p/cogen/source/browse/trunk/cogen/core/sockets.py#38">View source</a>
    </li>
</ul>
            <h3 id="function-setdefaulttimeout">
                setdefaulttimeout
                <span class="args">(timeout)</span>
            </h3>
            <div class="docstring rst"><p>Set the default timeout used by the socket wrapper
(<a class="reference" href="cogen.core.sockets.Socket.html">Socket</a> class)</p>
</div>
            <ul class="link-bar">
    <li class="link-to-sourcecode">
        <a href="http://code.google.com/p/cogen/source/browse/trunk/cogen/core/sockets.py#41">View source</a>
    </li>
</ul>
    </div>
        </div>
        <div id="footer">
            Generated with <a href="http://apydia.ematia.de/" class="extern">
            Apydia 0.0.3</a>
        </div>
    </div>
</body>
</html>